import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'


// https://vitejs.dev/config/
export default defineConfig({
  // 配置代理
  server: {
    proxy: {
      "/api": {
        target: "http://139.196.192.50:3000/",  // http://music.zzhitong.com/
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    },
  },

  plugins: [
    vue(),

    // 配置element-plus按需引入
    AutoImport({
      resolvers: [ElementPlusResolver()]
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],


  resolve: {
    // 配置路径别名
    alias: {
      "@": path.resolve(__dirname, "./src"),
      "@components": path.resolve(__dirname, "./src/components")
    }
  },

  // 全局注入scss变量
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: '@import "@/style/global/global.scss"; @import "@/style/global/common.scss"; @import "@/style/global/handle.scss";',
      }
    }
  }
})
